package com.dao.impl;

import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Component;
import com.bean.WeiboInfo;
import com.bean.WeiboShare;
import com.dao.WeiboShareDao;
import com.util.LoggerUtil;
@Component
public class WeiboShareDaoImpl implements WeiboShareDao{
	public static Logger logger=Logger.getLogger(WeiboShareDaoImpl.class);
	@Autowired
	private MongoTemplate mongoTemplate;

	@Override
	public Map<String, Object> insertWeiboShare(String mId, String lId,
			String type, String uid, String location, String url,
			String created_at, String followersCount, String friendsCount,
			String statusesCount, String favouritesCount, String weiboNickname,
			JSONObject logs) {
		Map<String, Object> map=new HashMap<>();
		try {
			WeiboInfo weiboInfo=new WeiboInfo();
			weiboInfo.setUid(uid);
			weiboInfo.setLocation(location);
			weiboInfo.setUrl(url);
			weiboInfo.setCreated_at(created_at);
			weiboInfo.setFavouritesCount(favouritesCount);
			weiboInfo.setFollowersCount(followersCount);
			weiboInfo.setFriendsCount(friendsCount);
			weiboInfo.setStatusesCount(statusesCount);
			weiboInfo.setWeiboNickname(weiboNickname);
			WeiboShare share=new WeiboShare();
			share.setmId(new ObjectId(mId));
			share.setType(type);
			share.setWeiInfo(weiboInfo);
			mongoTemplate.insert(mId);
			map.put("code", "0");
			LoggerUtil.backlogsSuccess(logs, logger);
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", "101");
			LoggerUtil.backlogsFalseError(logs, logger,e);
			return map;
		}
		return map;
	}
	
	
}
